unit uniManDesconto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uniManPadrao, DB, ADODB, Grids, DBGrids, StdCtrls, ExtCtrls,
  Buttons;

type
  TfrmManDesconto = class(TfrmManPadrao)
    QR_Gridcd_desconto: TAutoIncField;
    QR_Griddescricao: TWideStringField;
    QR_Griddesconto: TIntegerField;
    procedure btnPesquisaClick(Sender: TObject);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnEditarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    procedure p_Select(pParametros:String);
  public
    { Public declarations }
  end;

var
  frmManDesconto: TfrmManDesconto;

implementation

uses uniCadDesconto;

{$R *.dfm}

{ TfrmManDesconto }

procedure TfrmManDesconto.p_Select(pParametros: String);
var sSQL : String;
begin
  sSQL := ' SELECT * FROM TB_DESCONTO '+
          ' WHERE 1=1 ';
  sSQL := sSQL + pParametros;
  QR_Grid.Close;
  QR_Grid.SQL.Clear;
  QR_Grid.SQL.Add(sSQL);
  QR_Grid.Open;

end;

procedure TfrmManDesconto.btnPesquisaClick(Sender: TObject);
var sParametros : String;
begin
  inherited;
  if edtCodigo.Text <> '' then
    sParametros := sParametros + ' AND cd_desconto = '+edtCodigo.Text;

  if edtDescricao.Text <> '' then
    sParametros := sParametros + ' AND descricao LIKE '+QuotedStr('%'+edtDescricao.Text+'%');

  p_Select(sParametros);

end;

procedure TfrmManDesconto.btnIncluirClick(Sender: TObject);
begin
  inherited;
   try
    Application.CreateForm(TfrmCadDesconto, frmCadDesconto);
    frmCadDesconto.sEstado := 'I';
    frmCadDesconto.sCdCampo := '';
    frmCadDesconto.ShowModal;
  finally
    frmCadDesconto.Free;
  end;
  p_Select('');

end;

procedure TfrmManDesconto.btnEditarClick(Sender: TObject);
begin
  inherited;
try
    Application.CreateForm(TfrmCadDesconto, frmCadDesconto);
    frmCadDesconto.sEstado := 'E';
    frmCadDesconto.sCdCampo := QR_Grid.FieldByName('cd_desconto').AsString;
    frmCadDesconto.ShowModal;
  finally
    frmCadDesconto.Free;
  end;
  p_Select('');
end;

procedure TfrmManDesconto.FormShow(Sender: TObject);
begin
  inherited;
  p_Select('');
end;

end.
